package com.cisystem.web.controller.business;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.cisystem.common.config.CiSystemConfig;
import com.cisystem.common.core.controller.BaseController;
import com.cisystem.common.core.domain.AjaxResult;
import com.cisystem.common.core.domain.entity.SysDept;
import com.cisystem.common.core.domain.entity.SysDictData;
import com.cisystem.common.core.domain.entity.SysUser;
import com.cisystem.common.core.domain.model.LoginUser;
import com.cisystem.common.utils.DateUtils;
import com.cisystem.common.utils.SecurityUtils;
import com.cisystem.common.utils.StringUtils;
import com.cisystem.common.utils.file.FileUploadUtils;
import com.cisystem.common.utils.file.FileUtils;
import com.cisystem.common.utils.uuid.IdUtils;
import com.cisystem.framework.config.ServerConfig;
import com.cisystem.framework.web.service.PermissionService;
import com.cisystem.framework.web.service.SysPermissionService;
import com.cisystem.framework.web.service.TokenService;
import com.cisystem.system.domain.FileAssign;
import com.cisystem.system.domain.FileDir;
import com.cisystem.system.domain.FileStore;
import com.cisystem.system.domain.FileViewRecord;
import com.cisystem.system.domain.vo.assign.AssignEmailData;
import com.cisystem.system.domain.vo.assign.AssignEmailDataRequest;
import com.cisystem.system.service.*;
import com.cisystem.system.service.impl.SysMenuServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/business/dcc")
public class PdfController extends BaseController {

    @Autowired
    SysMenuServiceImpl menuService;

    @Autowired
    PermissionService permissionService;

    @Autowired
    TokenService tokenService;

    @Autowired
    SysPermissionService sysPermissionService;

    @Autowired
    ISysUserService userService;

    @Autowired
    IFileVerbService fileVerbService;

    @Autowired
    IFileStoreService fileStoreService;

    @Autowired
    IFileDirService fileDirService;

    @Autowired
    ISysDeptService deptService;

    @Autowired
    SendEmailService emailService;

    @Autowired
    IFileAssignService fileAssignService;

    @Autowired
    IFileViewRecordService viewRecordService;

    @Autowired
    private ServerConfig serverConfig;

    @Autowired
    ISysDictDataService dictDataService;


    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('business:dcc:list')")
    public AjaxResult listPdfFiles(String filePath,String searchValue) throws FileNotFoundException {
        Map<String, Object> subMap = new HashMap<>();

        subMap.put("files", new ArrayList<String>());
        subMap.put("dir", new ArrayList<HashMap<String, Object>>());
        subMap.put("path", filePath);
        FileUtils.readFile(subMap);
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> permissions = loginUser.getPermissions();
        if (permissionService.hasPermissions(permissions,"")){
            // 如果有所有权限，直接返回
            return success(subMap);
        }else{
            String prefix = "business:dccfile:";
            List<Map<String, Object>> dirs = (List<Map<String, Object>>)subMap.get("dir");
            List<Map<String, Object>> newDirs = new ArrayList<>();
            if (CollectionUtils.isEmpty(dirs)){
                return success(subMap);
            }
            //获取权限文件夹
            for (String permission : permissions) {
                // 判断是否是文件夹相关的权限
                if (permission.startsWith(prefix)){
                    // 获取文件夹名称
                    String fireDir = permission.substring(prefix.length());
                    // 获取指定文件夹
                    for (Map<String, Object> dir : dirs) {
                        String path = (String) dir.get("path");
                        String[] split = path.split("\\\\");
                        String dirName = split[split.length - 1];
                        if (fireDir.equals(dirName)){
                            newDirs.add(dir);
                        }
                    }
                }
            }
            subMap.put("dir",newDirs);
            return success(subMap);
        }
    }
    /**
     * 读取除了文件路径以外 所有的一级文件目录
     */
    @GetMapping("/listDirectory/{type}")
    @PreAuthorize("@ss.hasPermi('business:dcc:list')")
    public AjaxResult listDirectory(@PathVariable("type") String type) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> permissions = loginUser.getPermissions();
        String filePath ;
        String copyPath ;
        if ("dcc".equals(type)){
            filePath = CiSystemConfig.getDccPath();
            copyPath = CiSystemConfig.getCopyDccPath();
        }else{
            filePath = CiSystemConfig.getDccPath();
            copyPath = CiSystemConfig.getCopyFirstPath();
        }
        FileDir fileDir = new FileDir();
        List<FileDir> fileDirs = fileDirService.selectFileDirList(fileDir);
        if (CollectionUtils.isEmpty(fileDirs)){
            return AjaxResult.error("没有文件目录");
        }
        FileDir fileDir1 = fileDirs.stream().filter(i -> "0".equals(i.getFartherId()) && i.getFolderPath().startsWith(copyPath)).findAny().orElse(null);
        if (fileDir1 == null){
            return AjaxResult.error("没有根目录");
        }
        // 找出所有一级文件目录
        List<FileDir> firstFileDirs = new ArrayList<>();
        for (FileDir dir : fileDirs) {
            if (dir.getFartherId().equals(fileDir1.getId()) && dir.getFolderPath().startsWith(copyPath)){
                firstFileDirs.add(dir);
            }
        }
        Map<String, Object> subMap = new HashMap<>();
        List<HashMap<String, Object>> list = new ArrayList<>();
        subMap.put("files", new ArrayList<String>());
        subMap.put("dir", list);
        subMap.put("path", filePath);
        subMap.put("dirName", fileDir1.getFolderName());
        subMap.put("dirId",  fileDir1.getId());
        subMap.put("dirFatherId",fileDir1.getFartherId());
        firstFileDirs = firstFileDirs.stream().sorted(Comparator.comparing(FileDir::getFolderPath)).collect(Collectors.toList());
        // 权限前缀
        String prefix ;
        if ("dcc".equals(type)){
            prefix = "business:dccfile:";
        }else{
            prefix = "business:firstfile:";
        }
        for (FileDir store : firstFileDirs) {
            boolean flag = false;
            // 如果有所有权限 不限制
            if (permissionService.hasPermissions(permissions,"")){
                flag = true;
            }else{
                //获取权限文件夹
                for (String permission : permissions) {
                    // 判断是否是文件夹相关的权限
                    if (permission.startsWith(prefix)) {
                        // 获取文件夹名称
                        String fireDir = permission.substring(prefix.length());
                        if (fireDir.equals(store.getFolderName())) {
                           flag = true;
                        }
                    }
                }
            }
            // 一级文件不区分文件夹权限
            if (flag && "dcc".equals(type)){
                HashMap<String, Object> objectObjectHashMap = new HashMap<>();
                genMap(fileDirs,store,new ArrayList<>(),objectObjectHashMap);
                list.add(objectObjectHashMap);
            }
        }
        return success(subMap);
    }
    /**
     * 读取指定一级文件路径下的所有文件
     */
    @GetMapping("/listAllByDirectory/{type}")
    @PreAuthorize("@ss.hasPermi('business:dcc:list')")
    public AjaxResult listAllByDirectory(@PathVariable("type") String type, String dirId) {
        // 找到一级文件夹下的所有子文件夹
        List<FileDir> fileDirs = fileDirService.selectFileDirList(new FileDir());
        if (CollectionUtils.isEmpty(fileDirs)){
            return AjaxResult.error("没有文件目录");
        }
        FileDir fileDir = fileDirs.stream().filter(i -> dirId.equals(i.getId())).findAny().orElse(null);
        if (fileDir == null){
            return AjaxResult.error("没有指定文件目录");
        }
        // 判断是否有权限
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> permissions = loginUser.getPermissions();
        boolean flag = false;
        // 权限前缀
        String prefix ;
        if ("dcc".equals(type)){
            prefix = "business:dccfile:";
        }else{
            prefix = "business:firstfile:";
        }
        if (!permissionService.hasPermissions(permissions,"")) {
            //获取权限文件夹
            for (String permission : permissions) {
                // 判断是否是文件夹相关的权限
                if (permission.startsWith(prefix)) {
                    // 获取文件夹名称
                    String fireDir = permission.substring(prefix.length());
                    if (fireDir.equals(fileDir.getFolderName())) {
                        flag = true;
                    }
                }
            }
        }else{
            flag = true;
        }
        // 只对dcc限制权限
        if (!flag && "dcc".equals(type)){
            return AjaxResult.error("没有权限访问"+fileDir.getFolderName()+"文件夹");
        }
        List<String> childDirIds = new ArrayList<>();
        childDirIds.add(dirId);
        // 找出文件夹下的所有子文件夹
        findChildDir(childDirIds,fileDirs,dirId);
        // 查找所有的文件
        List<FileStore> fileStores = fileStoreService.getAllByDirIds(childDirIds);
        if (CollectionUtils.isEmpty(fileStores)){
            return AjaxResult.error("没有文件");
        }
        Iterator<FileStore> iterator = fileStores.iterator();
        while (iterator.hasNext()){
            FileStore next = iterator.next();
            if ("first".equals(type) && "n".equals(next.getVisible()) && !permissionService.hasPermissions(permissions,"business:first:visible")){
                iterator.remove();
            }
            if ("dcc".equals(type) && "n".equals(next.getVisible()) && !permissionService.hasPermissions(permissions,"business:dcc:visible")){
                iterator.remove();
            }
        }
        Map<String, Object> subMap = new HashMap<>();
        genMap(fileDirs,fileDir,fileStores,subMap);
        return success(subMap);
    }

    /**
     * 生成一级文件下 的所有文件夹和目录
     */
    private void genMap( List<FileDir> fileDirs ,FileDir fileDir, List<FileStore> fileStores, Map<String, Object> subMap) {
        String id = fileDir.getId();
        String filePath = fileDir.getFolderPath();
        String folderName = fileDir.getFolderName();
        // 找出文件目录下所有文件
        List<FileStore> files = new ArrayList<>();
        for (FileStore fileStore : fileStores) {
            // 如果是文件则加入
            if (id.equals(fileStore.getDirId())){
                files.add(fileStore);
            }
        }
        // 找出下级文件夹，生成子文件夹的所有数据
        List<HashMap<String, Object>> dirFiles = new ArrayList<>();
        for (FileDir dir : fileDirs) {
            if (id.equals(dir.getFartherId())){
                HashMap<String, Object> ssubMap= new HashMap<>();
                genMap(fileDirs,dir,fileStores,ssubMap);
                dirFiles.add(ssubMap);
            }
        }
        subMap.put("files", files);
        subMap.put("dir", dirFiles);
        subMap.put("path", filePath);
        subMap.put("dirName", folderName);
        subMap.put("dirId", id);
        subMap.put("dirFatherId",fileDir.getFartherId());
    }

    /**
     * 查找所有子文件夹
     */
    private void findChildDir(List<String> childDirIds, List<FileDir> fileDirs, String dirId) {
        for (FileDir fileDir : fileDirs) {
            if (dirId.equals(fileDir.getFartherId())){
                childDirIds.add(fileDir.getId());
                findChildDir(childDirIds,fileDirs,fileDir.getId());
            }
        }
    }
    /**
     * 同步文件
     */
    @GetMapping("/syncFiles")
    @PreAuthorize("@ss.hasPermi('business:dcc:config')")
    public AjaxResult syncFiles(){
        fileStoreService.syncFileStore();
        return success();
    }

    /**
     * 获取所有的可以分配的人员
     */
    @GetMapping("/getAssignSource/{fileId}")
    @PreAuthorize("@ss.hasPermi('business:dcc:assign')")
    public AjaxResult getAssignSource(@PathVariable("fileId") String fileId){
        return getAssignSourcePublic(fileId);
    }
    public AjaxResult getAssignSourcePublic(String fileId){
        FileAssign fileAssign = new FileAssign();
        fileAssign.setFileId(fileId);
        List<FileAssign> fileAssigns = fileAssignService.selectFileAssignList(fileAssign);
        List<AssignEmailData> assignEmailDataList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(fileAssigns)){
            FileAssign fileAssign1 = fileAssigns.get(0);
            String viewPermit = fileAssign1.getViewPermit();
            if (!StringUtils.isEmpty(viewPermit)){
                assignEmailDataList = JSONArray.parseArray(viewPermit, AssignEmailData.class);
            }
        }

        // 获取部门，取部门中的负责人
        List<SysDept> sysDepts = deptService.selectDeptList(new SysDept());
        // 获取所有的人员
        SysUser sysUser = new SysUser();
        sysUser.setStatus("0");
        List<SysUser> sysUsers = userService.selectUserList(sysUser);
        List<SysDept> deptTree = deptService.buildDeptTree(sysDepts);
        AssignEmailData assignEmailData = new AssignEmailData();
        assignEmailData.setId(0L);
        assignEmailData.setName("【根节点】");
        assignEmailData.setLeader("");
        assignEmailData.setOwner("");
        assignEmailData.setEmail("");
        assignEmailData.setPhone("");
        assignEmailData.setType("dept");
        assignEmailData.setDisabled(true);
        List<AssignEmailData> children = new ArrayList<>();
        assignEmailData.setChildren(children);
        genDeptWithPerson(deptTree,sysUsers,children,assignEmailDataList);
        List<AssignEmailData> array = new ArrayList<>();
        array.add(assignEmailData);
        return success(array);
    }
    private void genDeptWithPerson(List<SysDept> deptTree,List<SysUser> users,List<AssignEmailData> children, List<AssignEmailData> assignEmailDataList){
        if (!CollectionUtils.isEmpty(deptTree)){
            for (SysDept sysDept : deptTree) {
                AssignEmailData assignEmailData = new AssignEmailData();
                assignEmailData.setId(sysDept.getDeptId());
                assignEmailData.setName("【"+sysDept.getDeptName()+"】");
                assignEmailData.setLeader(sysDept.getDeptName());
                assignEmailData.setOwner(sysDept.getDeptName());
                assignEmailData.setEmail(sysDept.getEmail());
                assignEmailData.setPhone(sysDept.getPhone());
                assignEmailData.setDeptId(sysDept.getDeptId());
                assignEmailData.setType("dept");
                if (!CollectionUtils.isEmpty(assignEmailDataList)){
                    assignEmailDataList.stream().filter(i -> i.getId().equals(sysDept.getDeptId()) && i.getType().equals("dept")).findAny().ifPresent(i -> assignEmailData.setDisabled(true));
                }
                List<AssignEmailData> subchildren = new ArrayList<>();
                assignEmailData.setChildren(subchildren);
                List<SysDept> deptChildren = sysDept.getChildren();
                genDeptWithPerson(deptChildren,users,subchildren,assignEmailDataList);
                children.add(assignEmailData);
                if (!CollectionUtils.isEmpty(users)){
                    for (SysUser sysUser : users) {
                        if (sysDept.getDeptId().equals(sysUser.getDeptId())){
                            AssignEmailData assignEmail = new AssignEmailData();
                            assignEmail.setId(sysUser.getUserId());
                            assignEmail.setName(sysUser.getUserName());
                            assignEmail.setLeader(sysDept.getDeptName());
                            assignEmail.setOwner(sysDept.getDeptName());
                            assignEmail.setEmail(sysUser.getEmail());
                            assignEmail.setPhone(sysUser.getPhonenumber());
                            assignEmail.setType("user");
                            assignEmail.setChildren(new ArrayList());
                            assignEmail.setDeptId(sysDept.getDeptId());
                            if (!CollectionUtils.isEmpty(assignEmailDataList)){
                                assignEmailDataList.stream().filter(i -> i.getId().equals(sysUser.getUserId()) && i.getType().equals("user")).findAny().ifPresent(i -> assignEmail.setDisabled(true));
                            }
                            subchildren.add(assignEmail);
                        }
                    }
                }
            }
        }
    }
    /**
     * 发送邮件通知,生成记录
     */
    @PostMapping("/assignEmail")
    @PreAuthorize("@ss.hasPermi('business:dcc:assign')")
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult assignEmail(@RequestBody AssignEmailDataRequest request){
        return assignEmailPublic(request);
    }
    public AjaxResult assignEmailPublic(AssignEmailDataRequest request){
        // 创建文件分配记录
        LoginUser loginUser = getLoginUser();
        FileAssign fileAssign1 = new FileAssign();
        fileAssign1.setFileId(request.getFileId());
        List<FileAssign> fileAssigns = fileAssignService.selectFileAssignList(fileAssign1);
        FileAssign fileAssign;
        if (!CollectionUtils.isEmpty(fileAssigns)){
            fileAssign = fileAssigns.get(0);
            String viewPermit = fileAssign.getViewPermit();
            List<AssignEmailData> assignEmailData = JSONArray.parseArray(viewPermit, AssignEmailData.class);
            assignEmailData.addAll(request.getSendData());
            fileAssign.setViewPermit(JSONObject.toJSONString(assignEmailData));
            fileAssign.setUpdateBy(loginUser.getUser().getUserName());
            fileAssign.setUpdateTime(new Date());
            fileAssignService.updateFileAssign(fileAssign);
        }else{
            fileAssign = new FileAssign();
            fileAssign.setId(IdUtils.simpleUUID());
            fileAssign.setFileId(request.getFileId());
            fileAssign.setFileName(request.getFileName());
            fileAssign.setFilePath(request.getFilePath());
            fileAssign.setAssignTime(request.getFileDate());
            fileAssign.setViewPermit(JSONObject.toJSONString(request.getSendData()));
            fileAssign.setFileType(request.getFileType());
            fileAssign.setLevel(request.getEmergencyLevel());
            fileAssign.setDueDate(request.getDueDate());
            fileAssign.setSender(loginUser.getUser().getUserId());
            fileAssign.setSenderName(loginUser.getUser().getUserName());
            fileAssign.setCreateBy(loginUser.getUser().getUserName());
            fileAssign.setCreateTime(new Date());
            fileAssign.setUpdateBy(loginUser.getUser().getUserName());
            fileAssign.setUpdateTime(new Date());
            fileAssign.setRemark(request.getRemarkName());
            fileAssignService.insertFileAssign(fileAssign);
        }
        // 创建被分配的记录
        List<AssignEmailData> sendData = request.getSendData();
        List<FileViewRecord> recordList = new ArrayList<>();
        if (CollectionUtils.isEmpty(sendData)){
            return AjaxResult.error("没有分配的人员");
        }else{
            for (AssignEmailData assignEmailData : sendData) {
                String type = assignEmailData.getType();
                // 如果包含部门，则选择了部门下所有的人
                if ("user".equals(type)) {
                    FileViewRecord record = new FileViewRecord();
                    record.setId(IdUtils.simpleUUID());
                    record.setSender(loginUser.getUser().getUserId());
                    record.setAssignId(assignEmailData.getId());
                    record.setAssignDeptId(assignEmailData.getDeptId());
                    record.setAssignName(assignEmailData.getName());
                    record.setFileAssignId(fileAssign.getId());
                    record.setAssignType("user");
                    record.setEmail(assignEmailData.getEmail());
                    record.setFileId(request.getFileId());
                    record.setFilePath(request.getFilePath());
                    record.setFileName(request.getFileName());
                    record.setCreateTime(new Date());
                    record.setCreateBy(loginUser.getUser().getUserName());
                    record.setViewStatus("pending");
                    record.setLevel(request.getEmergencyLevel());
                    record.setFileType(request.getFileType());
                    record.setAssignTime(request.getFileDate());
                    record.setDueDate(request.getDueDate());
                    record.setUpdateTime(new Date());
                    record.setUpdateBy(loginUser.getUser().getUserName());
                    recordList.add(record);
                    // 发送邮件
                }
            }
        }
        if (!CollectionUtils.isEmpty(recordList) ){
            viewRecordService.batchInsertFileViewRecord(recordList);
        }
        SysDictData sysDictData = new SysDictData();
        sysDictData.setDictType("dcc_emergency_level");
        List<SysDictData> dictDataList = dictDataService.selectDictDataList(sysDictData);
        String level = request.getEmergencyLevel();
        if (!CollectionUtils.isEmpty(dictDataList)){
            level = dictDataList.stream().filter(i ->  request.getEmergencyLevel().equals(i.getDictValue())).findAny().orElse(new SysDictData()).getDictLabel();
        }
        // 通知部门负责人
        for (AssignEmailData assignEmailData : sendData) {
            String type = assignEmailData.getType();
            if ("dept".equals(type)){
                String title = "部门文件分配通知";
                String userName = assignEmailData.getOwner();
                String fileName = "文件<"+ request.getFileName()+">已经分配给您的部门，文件紧急等级："+level;
                String dueDate = "最后期限"+ DateUtils.dateTime(request.getDueDate());
                StringBuilder deptUser = new StringBuilder();
                deptUser.append("<p>").append("分配到的人员").append("</p>");
                List<AssignEmailData> children = assignEmailData.getChildren();
                if (!CollectionUtils.isEmpty(children)){
                    for (AssignEmailData child : children) {
                        deptUser.append("<p>").append(child.getName()).append("</p>");
                    }
                }
                String[] content = new String[]{title,userName,fileName,"文件名称："+dueDate, deptUser.toString()};
                emailService.sendAssignEmail("通知",content,assignEmailData.getEmail());
            }
        }
        // 发送邮件
        for (FileViewRecord fileViewRecord : recordList) {
            String title = "文件分配通知";
            String userName = fileViewRecord.getAssignName();
            String fileName = "文件<"+ fileViewRecord.getFileName()+">已经分配给您，请查看，文件紧急等级："+level;
            String dueDate = "最后期限"+ DateUtils.dateTime(fileViewRecord.getDueDate());
            String deptUser = "";
            String[] content = new String[]{title,userName,fileName,"文件名称："+dueDate,deptUser};
            emailService.sendAssignEmail("通知",content,fileViewRecord.getEmail());
        }
        return success();
    }
    /**
     * 获取文件权限配置
     */
    @GetMapping("/getFilesConfig")
    @PreAuthorize("@ss.hasPermi('business:dcc:config')")
    public AjaxResult getFilesConfig(){
        return success(menuService.selectFileDirConfig("business:dccfile:"));
    }
    /**
     * 添加文件权限配置
     */
    @GetMapping("/addFilesConfig")
    @PreAuthorize("@ss.hasPermi('business:dcc:config')")
    public AjaxResult addFilesConfig(String fileDirName){
        return success(menuService.addFileDirConfig("business:dccfile:",fileDirName));
    }
    /**
     * 删除文件权限配置
     */
    @GetMapping("/deleteFilesConfig")
    @PreAuthorize("@ss.hasPermi('business:dcc:config')")
    public AjaxResult deleteFilesConfig(Long menuId){
        menuService.deleteMenuById(menuId);
        // 更新缓存用户权限
        LoginUser loginUser = getLoginUser();
        if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
        {
            loginUser.setPermissions(sysPermissionService.getMenuPermission(loginUser.getUser()));
            loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
            tokenService.setLoginUser(loginUser);
        }
        return success();
    }

    /**
     * 通用上传请求（单个）
     */
    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file,String fileDir){
        try {
            System.out.println(fileDir);
            // 上传文件路径
            String filePath = CiSystemConfig.getDccPath();
            // 上传并返回新文件名称
            String fileName = FileUploadUtils.dccUpload(filePath+"/"+fileDir, file);
            String url = serverConfig.getUrl() + fileName;
            AjaxResult ajax = AjaxResult.success();
            ajax.put("url", url);
            ajax.put("fileName", fileName);
            ajax.put("newFileName", FileUtils.getName(fileName));
            ajax.put("originalFilename", file.getOriginalFilename());
            return ajax;
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改文件隐藏状态
     */
    @GetMapping("/editVisible/{fileId}/{visible}")
    @PreAuthorize("@ss.hasPermi('business:dcc:visible')")
    public AjaxResult editVisible(@PathVariable("fileId") String fileId,@PathVariable("visible") String visible){
        fileStoreService.editVisible(fileId,visible);
        return success();
    }

}